package com.foreknow.demo4;

/**
 * @author shkstart
 * @create 2021-07-26 15:16
 */
public class Master {
    public void feed(Pet pet){
        pet.eat();

    }
    public void  play(Pet pet){
        if(pet instanceof Dog){
            Dog dog=(Dog)pet;
            dog.run();
        }else if(pet instanceof Penguin){
            Penguin penguin=(Penguin)pet;
            penguin.swimming();
        }
    }

    public void cure(Pet p){
        if(p.getHealth()<50){
            p.toHospital();
            System.out.println("吃药.....");
        }
    }

    public static void main(String[] args) {
        Master master=new Master();
        Pet P=new Dog();
        P.setName("奥斯卡");
        P.setHealth(40);
        P.setLove(99);
        master.cure(P);
        master.feed(P);
        master.play(P);
        P =new Penguin();
        P.setName("QQ");
        P.setHealth(20);
        P.setLove(80);
        master.cure(P);
        master.feed(P);
        master.play(P);
    }
}
